package study.corejava.extend;

import java.util.Scanner;

/**
 * This program demonstrates enumerated types.
 * @version 1.0 2004-05-24
 * @author Cay Horstmann
 */
public class EnumTest {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);

		System.out.print("Enter a size: (SMALL, MEDIUM, LARGE, EXTRA_LARGE) ");

		String input = in.next().toUpperCase();
		
		//将size设置成Size.input (返回指定名字，给定类的枚举常量)
		Size size = Enum.valueOf(Size.class, input);
		
		System.out.println("size=" + size);
		System.out.println("abbreviation=" + size.getAbbreviation());
		if (size == Size.EXTRA_LARGE)
			System.out.println("Good job--you paid attention to the _.");
		
		System.out.println();
	}
}

//所有的枚举类型都是Enum类的子类
enum Size {
	//4个Size类型的实例
	SMALL("S嘎嘎嘎"), MEDIUM("M"), LARGE("L"), EXTRA_LARGE("XL");

	private Size(String abbreviation) {
		this.abbreviation = abbreviation;
	}

	public String getAbbreviation() {
		return abbreviation;
	}
	
	//额外的属性
	private String abbreviation;
}
